package gocache

import "sync"

type Cache interface {
	Table(table string) Table
}
type myCache struct {
	sync.RWMutex
	tables map[string]Table
}
func (this *myCache) Table(table string)Table{
	this.RLock()
	t,ok := this.tables[table]
	this.RUnlock()
	if ok{
		return t
	}
	this.Lock()
	defer this.Unlock()
	t,ok = this.tables[table]
	if ok{
		return t
	}
	this.tables[table] = NewTable()
	return this.tables[table]

}
func NewCache() Cache {
	return &myCache{
		tables:make(map[string]Table),
	}
}